package com.itheima.web.controller.oms;


import com.itheima.service.oms.IOmsOrderReturnReasonService;
import com.itheima.utils.ResultData;
import com.itheima.vo.oms.OmsOrderReturnReason;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 退货原因表 前端控制器
 * </p>
 *
 * @author 王志斌
 * @since 2022-07-06
 */
@RestController
@RequestMapping("/returnReason")
public class OmsOrderReturnReasonController {
    @DubboReference
    private IOmsOrderReturnReasonService orderReturnReasonService;
    /**
     * 分页查询退货原因
     *
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/list")
    public ResultData list(Integer pageNum, Integer pageSize) {
     //   PageResult result=orderReturnReasonService.pagelist(pageNum,pageSize);
       /* Page<OmsOrderReturnReason> omsOrderReturnReasonPage = new Page<>(pageNum,pageSize);
        orderReturnReasonService.page(omsOrderReturnReasonPage);
        PageResult page = PageResult.getPage(omsOrderReturnReasonPage);*/

        return ResultData.ok("操作成功",orderReturnReasonService.pagelist(pageNum,pageSize));

/*        BeanUtils.copyProperties();
        List<>omsOrderReturnReasonPage.getRecords().stream().map(omsOrderReturnReason -> {
            omsOrderReturnReason.get
            return
                }
                ).collect(Collectors.toList());*/
    }
    /**
     * 根据id，获取单个退货原因详情信息
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResultData select(@PathVariable Long id) {
        OmsOrderReturnReason orderReturnReason = orderReturnReasonService.select(id);
        return ResultData.ok("",orderReturnReason);
    }

    /**
     * 修改退货原因
     *
     * @param id
     * @return
     */
    @PostMapping("/update/{id}")
    public ResultData updateReturnReason(@PathVariable Long id, @RequestBody OmsOrderReturnReason reason) {
        Integer count = orderReturnReasonService.updateReturnReason(id, reason);
        if (count == null) {
            return ResultData.error("修改失败");
        }
        return ResultData.ok("修改成功","");
    }

    /**
     * 修改退货原因启用状态
     *
     * @param id
     * @param status
     * @return
     */
    @PostMapping("/update/status")
    public ResultData updateStatus(@RequestParam("ids") Long id, @RequestParam Integer status) {
        Integer count = orderReturnReasonService.updateStatus(id, status);
        if (count == null) {
            return ResultData.error("修改失败");
        }
        return ResultData.ok("修改成功","");
    }

    /**
     * 批量删除退货原因
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    public ResultData delete(@RequestParam List<Long> ids) {
        Integer count = orderReturnReasonService.delete(ids);
        if (count == null) {
            return ResultData.error("删除失败");
        }
        return ResultData.ok("删除成功","");
    }

    /**
     * 添加退货原因
     * @param reason
     * @return
     */
    @PostMapping("/create")
    public ResultData create(@RequestBody OmsOrderReturnReason reason) {
        Integer count = orderReturnReasonService.create(reason);
        if (count == null) {
            return ResultData.error("删除失败");
        }
        return ResultData.ok("删除成功","");
    }
}
